package com.htl.线程.ConcurrentModificationException;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

public class CyclicBarrierTest {
    public static void main(String[] args) {

        /**
         *  加法计数器
         */
        CyclicBarrier cyclicBarrier = new CyclicBarrier(5, ()->{
            System.out.println("放行");
        });

        for (int i = 0; i < 30; i++) {
            final int temp = i;
            new Thread(()->{
                // lambda表达式中只能访问final修饰的变量
                System.out.println("--->" + temp);
                try {
                    cyclicBarrier.await();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                } catch (BrokenBarrierException e) {
                    e.printStackTrace();
                }
            }).start();
        }

    }
}
